package com.ruoyi.lvlian.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.lvlian.domain.InvoiceInfo;
import com.ruoyi.lvlian.domain.WarehouseInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.License;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@ToString
@ApiModel(value = "完税vo信息", description = "完税vo信息")
public class WarehouseInfoVo extends WarehouseInfo {
 /*   @ApiModelProperty(value = "未结算金额=税价合计-已结算金额")
    private double notSettlementAmount;*/

    @ApiModelProperty(value = "车辆入网状态 0为入网 1已入网")
    private String netStatus;
    @ApiModelProperty(value = "车牌颜色  (黄色/蓝色/黄绿色)")
    private String plateColor;
    @ApiModelProperty(value = "购买方结算金额")
    private Double buyerSettlementAmountRef;
    @ApiModelProperty(value = "销售方结算金额")
    private double sellerSettlementAmountRef;


    private List<InvoiceVo> invoiceInfoList;

    public String getPlateColor() {
        if ("7001".equalsIgnoreCase(plateColor)) {
            return "3";
        }
        if ("7002".equalsIgnoreCase(plateColor)) {
            return "2";
        }
        if ("7003".equalsIgnoreCase(plateColor)) {
            return "1";
        }
        return plateColor;

    }

    @ApiModelProperty(value = "销售方结算状态")
    private String sellerSettlementStatus;

    @ApiModelProperty(value = "采购方结算状态")
    private String buyerSettlementStatus;

    public String getSellerSettlementStatus() {

        if (StringUtils.isEmpty(String.valueOf(sellerSettlementAmountRef)) || sellerSettlementAmountRef == 0) {
            return "未结算";
        }
        if (Double.compare(this.sellerSettlementAmountRef, getSellerSettlementAmount()) < 0) {
            return "部分结算";
        }
        if (Double.compare(this.sellerSettlementAmountRef, getSellerSettlementAmount()) == 0) {
            return "全部结算";
        }

        if (Double.compare(this.sellerSettlementAmountRef, getSellerSettlementAmount()) > 0) {
            return "重复数据";
        }
        return "未结算";
    }

    public String getBuyerSettlementStatus() {
        if (buyerSettlementAmountRef == null || StringUtils.isEmpty(String.valueOf(buyerSettlementAmountRef)) || buyerSettlementAmountRef == 0) {
            return "未结算";
        }
        if (Double.compare(this.buyerSettlementAmountRef, getBuyerSettlementAmount()) < 0) {
            return "部分结算";
        }
        if (Double.compare(this.buyerSettlementAmountRef, getBuyerSettlementAmount()) == 0) {
            return "全部结算";
        }
        if (Double.compare(this.buyerSettlementAmountRef, getBuyerSettlementAmount()) > 0) {
            return "重复数据";
        }
        return "未结算";
    }


    @ApiModelProperty(value = "出库结算金额")
    private double warehouseAmount;
    @ApiModelProperty(value = "本次结算对应的发票金额")
    private double fapiaoSettlementAmount;
    @ApiModelProperty(value = "发票金额")
    private double fapiaoAmount;

    @ApiModelProperty(value = "驾驶证正页")
    private String driverLicenseImg;
    @ApiModelProperty(value = "行驶证正页")
    private String drivingLicenseImg;

    public String getDriverLicenseImg() {
        if (com.ruoyi.common.core.utils.StringUtils.isNotEmpty(driverLicenseImg)) {
            return "https://data.lvlianhengsheng.com/dev-api/file/fileAttachmentInfo/viewImage?key=" + driverLicenseImg;
        }
        return driverLicenseImg;
    }

    public String getDrivingLicenseImg() {
        if (com.ruoyi.common.core.utils.StringUtils.isNotEmpty(drivingLicenseImg)) {
            return "https://data.lvlianhengsheng.com/dev-api/file/fileAttachmentInfo/viewImage?key=" + drivingLicenseImg;
        }

        return drivingLicenseImg;
    }


    /**
     * 生成图片 URL
     */


    /**
     * 存储所有 img 结尾的字段
     */
    private List<Map<String, String>> imgList = new ArrayList<>();

    /**
     * 获取图片列表
     * @return List<Map < String, String>>，每个 Map 包含 imgname 和 imgurl
     */
    /**
     * 获取图片列表
     *
     * @return List<Map < String, String>>，每个 Map 包含 imgname 和 imgurl
     */
    public List<Map<String, String>> getImgList() {
        List<Map<String, String>> imgList = new ArrayList<>();
        try {
            Class<?> clazz = this.getClass();
            while (clazz != null) { // 遍历当前类及其所有父类
                for (Field field : clazz.getDeclaredFields()) {
                    if (field.getType() == String.class && field.getName().toLowerCase().endsWith("img")) {
                        field.setAccessible(true);
                        String value = (String) field.get(this);
                        if (StringUtils.isNotEmpty(value)) { // 只添加非空图片
                            Map<String, String> imgMap = new HashMap<>();
                            imgMap.put("imgname", field.getName());
                            imgMap.put("imgurl", value);
                            imgList.add(imgMap);
                        }
                    }
                }
                clazz = clazz.getSuperclass(); // 获取父类
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return imgList;
    }


}
